package com.hgd.igreencar.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageInfo;
import com.hgd.igreencar.biz.IQuestionJutiPlusBiz;
import com.hgd.igreencar.biz.IVehicleExhaustPlusBiz;
import com.hgd.igreencar.entity.QuestionJutiPlus;
import com.hgd.igreencar.entity.VehicleExhaustPlus;
import com.hgd.igreencar.entity.WebsiteUsers;
import com.hgd.igreencar.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/QuestionJutiPlus")
public class QuestionJutiPlusController {
    @Autowired
    private IQuestionJutiPlusBiz questionJutiPlusBiz;

    /**
     * 查询所有的故障情况
     * 参数：地区areaName，品牌名brandName，故障原因questionReasion，默认值如下
     */
    @GetMapping("/faultlist")
    public Result queryFault(
            @RequestParam(required = false,defaultValue = "西宁")String areaName,
            @RequestParam(required = false,defaultValue = "兰博基尼")String brandName,
            @RequestParam(required = false,defaultValue = "引擎过热")String questionReasion,
            @RequestParam(required = false,defaultValue = "1")int currentPage,
           @RequestParam(required = false,defaultValue = "10")int pageSize){

        PageInfo<QuestionJutiPlus> pageInfo = questionJutiPlusBiz.queryFault(areaName,brandName,questionReasion,currentPage,pageSize);
        return Result.ok(pageInfo);
    }
    /**
     * 查询所有的故障情况
     */
    @GetMapping("/allFaultList")
    public Result queryAllFault(
            @RequestParam(required = false,defaultValue = "1")int currentPage,
            @RequestParam(required = false,defaultValue = "10")int pageSize){
        PageInfo<QuestionJutiPlus> pageInfo = questionJutiPlusBiz.queryAllFault(currentPage,pageSize);
        return Result.ok(pageInfo);
    }

    /**
     * 按需查询所有的排放情况（以JSON形式传不管是否超标）
     */
    @PostMapping("/FaultListByJson")
    public Result queryFaultByJson(@RequestBody String dataJson){
        JSONObject jsonObject = JSON.parseObject(dataJson);
        String areaName = jsonObject.getString("areaName");
        String brandName = jsonObject.getString("brandName");
        String questionReasion = jsonObject.getString("questionReasion");
        Integer currentPage = jsonObject.getInteger("currentPage");
        Integer pageSize = jsonObject.getInteger("pageSize");
        PageInfo<QuestionJutiPlus> pageInfo = questionJutiPlusBiz.queryFaultByJson(areaName,brandName,questionReasion, currentPage,pageSize);
        return Result.ok(pageInfo);
    }

    /**
     * 查询单车所有的故障情况
     * 参数：carId必须要有
     */
    @GetMapping("/Onefaultlist")
    public Result queryByIdFault(
            @RequestParam(required = true)Integer carId,
            @RequestParam(required = false,defaultValue = "1")int currentPage,
            @RequestParam(required = false,defaultValue = "10")int pageSize){
        PageInfo<QuestionJutiPlus> pageInfo = questionJutiPlusBiz.queryByIdFault(carId,currentPage,pageSize);
        return Result.ok(pageInfo);
    }


}
